package com.june.springframework.p2p;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;

public class TextMessageListener implements MessageListener {

	@Override
	public void onMessage(Message message) {
		if (message instanceof TextMessage) {			
			TextMessage textMessage = (TextMessage) message;
			if (textMessage != null) {			
				try {
					System.out.println("接收到点对点消息：" + textMessage.getText());
				} catch (JMSException e) {
					e.printStackTrace();
				}
			}
		} else if (message instanceof ObjectMessage) {
			ObjectMessage objectMessage = (ObjectMessage) message;
			if (objectMessage != null) {
				try {
					System.out.println("接收到点对点消息：" + objectMessage.getObject());
				} catch (JMSException e) {
					e.printStackTrace();
				}
			}
		}
	}

}
